﻿#ifndef MAILSENDER_H
#define MAILSENDER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>

struct MailAttachment
{
    QString name;
    QByteArray content;
};

class MailSender : public QObject
{
    Q_OBJECT
public:
    explicit MailSender(QObject *parent = nullptr);

    void setReceiverMail(const QString& mail);
    void setSubject(const QString& subject);
    void setTitle(const QString& title);

    void setHtml(const QString& html);
    void addAttachment(const QString& name, const QByteArray& content);

    void clearAttachments();

    void send();

signals:
    void finished(bool ok, const QString& msg);

private slots:
    void onReply(QNetworkReply* reply);

private:
    QString m_recevier, m_subject, m_title, m_html;
    QList<MailAttachment> m_attachments;
    QNetworkAccessManager m_net;
};

#endif // MAILSENDER_H
